package com.freight.order.enums;

import lombok.Getter;

/**
 * @author hytma
 */

@Getter
public enum OrderStatusEnum {
    ORDER_CANCEL(-1, "订单取消"),
    ORDER_DRAFT(0, "待接单"),
    ORDER_CONFIRM(1, "待装货"),
    ORDER_TRANS(2, "货物运输"),
    ORDER_COMPANY_SETTLE(3, "业务审核"),
    ORDER_DRIVER_SETTLE(4, "财务审核"),
    ORDER_COMPANY_PAY(5, "获取签收"),
    ORDER_PLAT_SETTLE(6, "平台结算"),
    ORDER_OVER(7, "订单结束");
    Integer code;
    String name;


    OrderStatusEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getName(int index) {
        for (OrderStatusEnum orderStatus : OrderStatusEnum.values()) {
            if (orderStatus.getCode() == index) {
                return orderStatus.name;
            }
        }
        return null;
    }

    public static OrderStatusEnum findByCode(Integer code) {
        for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
            if (code.equals(orderStatusEnum.code)) {
                return orderStatusEnum;
            }
        }
        throw new RuntimeException("状态不存在");
    }

}
